<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>qhy系统 - 房屋信息管理</title>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/main.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/lib/font-awesome/css/font-awesome.css">
</head>

<body>
<div class="box">
	<h3>角色管理<a href="${pageContext.request.contextPath}/RoleAddServlet"></a></h3>
	<div class="actions">
		<div>
			<a class="btn btn-primary" href="${pageContext.request.contextPath}/view/role/add.jsp">添加角色</a>
			<input class="btn btn-primary"  type = "button" onclick = "fun()" value = "删除选中的"/>		</div>
	</div>
   <div class="actions">
		<div>
			<form action="${pageContext.request.contextPath}/RoleMFindServlet">
				角色名字：<input type = "text" name = "name">
				权限：<input type = "text" name = "desc">
				<input type = "submit" value = "查询" >
			</form>
		</div>
	</div>
   	
	<table class="list">
	
		<tr>
			<th>选择</th>
			<th>序号</th>
			<th>角色名称</th>
			<th>角色权限</th>
			<th>添加时间</th>
			<th>角色操作</th>
		</tr>
		<c:forEach  items="${pb.beanList }"  var="role">
		<tr>
			<td><input type = "checkbox" name = "name" value = "${role.ro_id}"></td>
			<td>${role.ro_id}</td>
			<td>${role.ro_name}</td>
			<td>${role.ro_desc}</td>
			<td>${role.ro_create_time }</td>
			<td>
				<a class="fa fa-info" title="详情" href="detail.html"></a>
				&nbsp;&nbsp;
				<a class="fa fa-pencil" title="编辑" href="${pageContext.request.contextPath}/RolefindServlet?ro_id=${role.ro_id}"></a>
				&nbsp;&nbsp;
				<a class="fa fa-remove" title="删除" href="${pageContext.request.contextPath}/RoleDelServlet?ro_id=${role.ro_id}" onclick="confirmDelete(1)"></a>
			</td>
		</tr>
		</c:forEach>
	</table>
	<div class="pager-info">
		<div>共有 ${pb.tr } 条记录，第 ${pb.pc }/${pb.tp } 页 </div>
		<div>
			<ul class="pagination">
				<li class="paginate_button previous disabled }">
				<c:if test = "${pb.pc>1 }" >
				<a href="${pb.url }&pc=1">首页</a>
				</c:if>
				</li>
				<li class="paginate_button previous disabled }">
				<c:if test = "${pb.pc>1 }" >
				<a href="${pb.url }&pc=${pb.pc-1 }">上一页</a>
				</c:if>
				</li>
				<c:choose>
					<c:when test="${pb.pc<3 }">
						<c:set var = "begin" value = "1"></c:set>
						<c:set var = "end" value = "${pb.tp }"></c:set>
					</c:when>
					<c:otherwise>
						<c:set var = "begin" value = "${pb.pc-1 }"></c:set>
						<c:set var = "end" value = "${pb.pc+1 }"></c:set>
						<c:if test="${pb.pc-1<1 }">
						<c:set var = "begin" value = "1"></c:set>
						<c:set var = "end" value = "3"></c:set>
						</c:if>
						<c:if test="${pb.pc+1>pb.tp }">
						<c:set var = "begin" value = "${pb.tp-2 }"></c:set>
						<c:set var = "end" value = "${pb.tp }"></c:set>
						</c:if>	
					</c:otherwise>
					
				</c:choose>
				
				<c:forEach var = "i" begin = "${begin }" end = "${end }">
					<c:choose>
						<c:when test="${pb.pc == i }">
							<li class="paginate_button active"><a href = "#">${i }</a></li>
						</c:when>
						<c:otherwise>
							<li class="paginate_button next disabled"><a href="${pb.url }&pc=${i }">${i }</a></li>
						</c:otherwise>
					</c:choose>
				</c:forEach>
				
				<li class="paginate_button next disabled">
				<c:if test = "${pb.pc<pb.tp }" >
				<a href="${pb.url }&pc=${pb.pc+1 }">下一页</a>
				</c:if>
				</li>
				<li class="paginate_button next disabled">
				<c:if test = "${pb.pc<pb.tp }" >
				<a href="${pb.url }&pc=${pb.tp }">尾页</a>
				</c:if>
				</li>
			</ul>
		</div>
	</div>
</div>
<script src="${pageContext.request.contextPath}/lib/jquery/jquery.js"></script>
<script>
function confirmDelete(id){
	if (confirm("确定要删除码？")) {
		alert('发送删除请求，刷新页面（不要异步）');
	}
	return false;
}
</script>
<script type="text/javascript">
if(!(typeof(<%=request.getAttribute("msg") %>)=="object")){
	alert("${msg }")
}
	function fun(){
		var name = document.getElementsByName("name");
		var list = [];
		for(var i = 0;i<name.length;i++){
			if(name[i].checked){
				list.push(name[i].value);
			}
		}
		window.location="RoleDelsServlet?list="+list;
	}
	
</script>
</body>
</html>